package org.example;

import org.example.test.Computer;
import org.example.test.Mobile;
import org.example.test.Person;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;

public class Main {
    public static void main(String[] args) {
        //创建一个容器：非常类似List l = new ArrayList()
        //Annotation是注解，ApplicationContext是上下文环境（理解为容器）
        //new出来是一个注解配置的容器，传入的参数，需要扫描的包路径
        //表示的含义：在指定的包路径下，进行扫描，如果是spring框架的注解的类，就会注册到容器中
        ApplicationContext context = new AnnotationConfigApplicationContext(
                "org.example");
        Person p = (Person) context.getBean("person");
        System.out.println(p);
        Mobile mobile = (Mobile) context.getBean("mobile");
        //打印person对象的mobile属性，验证是否是容器中注入的mobile
        System.out.println("===person[mobile]: "+p.getMobile());
        System.out.println("===person[m2]: "+p.getM2());
        System.out.println("===person[m]: "+p.getM());
        System.out.println("===person[m1]: "+p.getM1());
        System.out.println("===person[mm]: "+p.getMm());
        System.out.println("===person[m0]: "+p.getM0());
        System.out.println(mobile);
        System.out.println(p.getMobile() == mobile);

        Person p1 = (Person) context.getBean("p1");
        System.out.println(p1);
        System.out.println(p == p1);

        Person p2 = (Person) context.getBean("p2");
        System.out.println(p2);
        System.out.println(p1 == p2);

        Computer c = (Computer) context.getBean("comp");
        System.out.println(c);
    }
}